import logging
from redis import StrictRedis


class Config(object):
    """项目配置"""
    DEBUG = True
    SECRET_KEY = "1ZtcjyZHcTaV7sEXGYKdq1UPME8GJW2uQNgpy/7YKjd6PevrIRQIwIIQwrs5Y4C+"

    # 为mysql数据库添加配置
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/information"
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True
    # 为reids数据库添加配置
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379
    # 设置Session保存配置
    SESSION_TYPE = "redis"
    # 是否给Session进行签名
    SESSION_USE_SIGNER = True
    # 指定Session保存的 redis
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT)
    # 设置Session需要过期
    SESSION_PERMANENT = False
    # 设置Session过期时间
    PERMANENT_SESSION_LIFETIME = 86400 * 2


class DevelopmentConfig(Config):
    """调试环境下的配置"""
    DEBUG = True
    # 配置日志等级
    LOG_LEVEL = logging.DEBUG


class ProductionConfig(Config):
    """生产环境下的配置"""
    DEBUG = False
    LOG_LEVEL = logging.ERROR


class TestingConfig(Config):
    """测试环境下的配置"""
    DEBUG = True
    TESTING = True


config = {"development": DevelopmentConfig,
          "production": ProductionConfig,
          "testing": TestingConfig}